// 十进制转二进制
const dec2bin = (dec) => {
  let str = '';
  let stack = []

  while (dec > 0) {
    stack.push(dec % 2);
    dec = parseInt(dec / 2);
    // dec = dec >> 1; 
  }
  while (stack.length) {
    
    str += stack.pop()
  }

  return str;
}
// console.log(dec2bin(10)); // 1010


// 判断是否都是有效括号
const isValid = (s) => {
  if (s.length % 2 !== 0) return false; // 都不是成对的数量，无效
  const stack = [];
  for (let i = 0; i < s.length; i++) {
    const item = s[i];
    if (['(', '{', '['].includes(item)) {
      stack.push(item)
      continue
    }
    if (!stack.length) return false; // 第一个就是右括号， 无效
    // 取栈顶
    const last = stack[stack.length - 1];
    if ((item === ')' && last === '(') || (item === ']' && last === '[') || (item === '}' && last === '{')) {
      // 如果匹配成功，栈顶出栈
      stack.pop();
      continue
    }
    return false
  }
  return stack.length === 0;
}
// console.log(isValid('(()){}{]')) // false